
var _ = require('lodash'),
    entityCollection = require('../../../Base/server/controllers/EntityCollection');

//通过质检指标查找不良类型
exports.findBadTypeByQCNormID = function(qcNormId, completeFun){
    var entity = entityCollection.getEntity('BadTypeBind'),
        qcNormIds = _.isString(qcNormId) ? [qcNormId] : qcNormId;
    entity.find({QCNorm: {$in: qcNormIds}}, null, null, function (err, records) {
        if (err) {
            var newErr = new Error();
            newErr.leval = 9;
            newErr.title = '查询品质记录错误';
            newErr.message = '查询失败，请检查查询参数！';
            completeFun(newErr);
        } else {
            completeFun(null, records);
        }
    });
};
//通过不良类型查找质检指标
exports.findQCNormIDByBadType = function(badType, completeFun){
    var entity = entityCollection.getEntity('BadTypeBind');
    entity.findOne({
            BadType: badType
        }, [{
            path: 'QCNorm'
        }],
        function(err, record) {
            if (err) {
              var newErr = new Error();
              newErr.leval = 9;
              newErr.title = '查询质检指标错误';
              newErr.message = '查询失败，请检查查询参数！';
              completeFun(newErr);
            } else {
              completeFun(null, record);
            }
        }
    );    
    
};